package com.three.controller;

import com.baor.baseUtil.R;
import com.three.domain.Classes;
import com.three.domain.Students;
import com.three.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class ClassesController {

    @Autowired
    private ClassesService classesService;
//总端
    //查询所有班级
    @RequestMapping(value="/classesList")
    public R classesList(@RequestBody Map<String, Object> map) {
        String keyword = (String)map.get("keyword");
        String start_date = (String)map.get("start_date");
        String end_date = (String)map.get("end_date");
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        return classesService.classesList(keyword, start_date, end_date, pageIndex, pageSize);
    }

    //查询班级下的学生
    @RequestMapping(value="/classStudentList")
    public R classStudentList(@RequestBody Map<String, Object> map) {
        String class_name = (String)map.get("class_name");
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        return classesService.classStudentList(class_name, pageIndex, pageSize);
    }

    //添加班级
    @RequestMapping(value = "/addClasses")
    public R addClasses(@RequestBody Classes classes) {
        return classesService.addClasses(classes);
    }
    //学科下拉框
    @RequestMapping(value = "/subjectList")
    public R subjectList() {
        return classesService.subjectList();
    }
    //负责人下拉框
    @RequestMapping(value = "/teacherList")
    public R teacherList() {
        return classesService.teacherList();
    }
    //班级详情添加学生列表
    @RequestMapping(value = "/studentList")
    public R studentList() {
        return classesService.studentList();
    }
    //添加班级学生
    @RequestMapping(value = "/addStudent")
    public R addStudent(@RequestBody Map<String,Object> map) {
        Integer student_id = (Integer) map.get("student_id");
        String class_name = (String) map.get("class_name");
        return classesService.addstu(class_name,student_id);
    }


    //删除学生
    @RequestMapping(value = "/deleteStudent")
    public R deleteStudent(@RequestBody Students students) {

        return classesService.deleteStudent(students.getStudent_id());
    }

    //修改班级
    @RequestMapping(value = "/updateClasses")
    public R updateClasses(@RequestBody Classes classes) {
        return classesService.updateClasses(classes);
    }

//教师端
    @RequestMapping(value = "/classesListByTeacher")
    public Object classesListByTeacher(@RequestBody Map<String,Object> map) {
        return classesService.classesListByTeacher(map);
    }
    @RequestMapping(value = "/updateClassesByTeacher")
    public R updateClassesByTeacher(@RequestBody Classes classes) {
        return classesService.updateClassesByTeacher(classes);
    }
}
